<?php
namespace app\api\controller;

use app\api\controller\Base;
use think\Db;



class Index extends Base
{
    public function _empty()
    {
        header("Location:/404.html");
        exit;
    }
    public function ajax()
    {
        $data=input('post.');
		if(!Base::lizhili($data)){
			header("Location:/404.html");
			exit;
		}
		//获取首页数据
		if ($data['type']=='get_index_list') {
			if($data['cateid']==0){ //推荐
				$info=Db::name('article')->where('state',1)->field('id,title,author,time,click_wai as views')->page($data['page'],9)->select();
			}else{
				$info=Db::name('article')->where('cateid',$data['cateid'])->field('id,title,author,time,click_wai as views')->page($data['page'],9)->select();
			}
			if($info){
				foreach($info as $k=>$v){
					$info[$k]['imgs']=Db::name('article_img')->where('aid',$v['id'])->column('pic');
				}
				return ['code'=>1,'message'=>'成功','data'=>$info];
			}else{
				return ['code'=>0,'message'=>'失败'];
			}
			
		}
		
        return ['code'=>0,'message'=>'非法获取'];
    }
	
}
